<?php
/*
YHM (Your Hosting Manager) - Copyright 2010 All Rights Reserved. - YHM Group
Released under the Simplified BSD Licence.

Website: http://yhm.co.uk
Licence: http://yhm.co.uk/about/#licence

file: client/kb.php
author: Kieran D. (Polarbear541)
*/

//Init Includes, Sessions and Page Info
require_once("../global.php");
session_start();
checklogin_client();
$username = $_SESSION['user_name'];
$page = "support";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YHM - Client CP - Knowledge Base</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
</head>
<body>

<?php include("./header.php"); ?>

<div id="content">

	<h2>Knowledge Base Articles</h2>

	<?php
	//Assign Variables
	$kid = mysql_real_escape_string($_GET['kid']);

	if(empty($kid)) //If KB Article ID is empty then show all
	{	
		//Query to run
		$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."knowledgebase ORDER BY id DESC LIMIT 0,5");
		$rows = mysql_num_rows($query);

		//Display Articles
		while($row = mysql_fetch_array($query))
		{
			echo "<h3><a href='./kb.php?kid={$row['id']}>{$row['title']}</a></h3>";
		}
		
		if ($row == "0")
		{
			echo "No articles to display";
		}
	}

	else //Else show specific article
	{
		//Run queries to get article info
		$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."knowledgebase WHERE id='$kid'");
		$row = mysql_fetch_array($query);
		
		if (!$row) //If no result show not found error
		{
			echo "Article Not Found <br />";
		}		
	
		else //Else show article info
		{
			echo "<h3>Article: {$row['title']}</h3>";
			echo $row['content'];
		}	
	
		//Show back link
		echo "<br /><br /><a href='./kb.php'>Back to articles</a>";
	}
	?>

	<?php require_once("../footer.php"); ?>

</div>
</body>
</html>